local jiaohao = fk.CreateSkill {
  name = "jiaohao",
}

local getShade = function (room, n)
  local ids = {}
  for _, id in ipairs(room.void) do
    if n <= 0 then break end
    if Fk:getCardById(id).name == "shade" then
      room:setCardMark(Fk:getCardById(id), MarkEnum.DestructIntoDiscard, 1)
      table.insert(ids, id)
      n = n - 1
    end
  end
  while n > 0 do
    local card = room:printCard("shade", Card.Spade, 1)
    room:setCardMark(card, MarkEnum.DestructIntoDiscard, 1)
    table.insert(ids, card.id)
    n = n - 1
  end
  return ids
end

jiaohao:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  attached_skill_name = "jiaohao&",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Start then
      return #player:getCardIds("e") < #player:getAvailableEquipSlots()
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = (#player:getAvailableEquipSlots() - #player:getCardIds("e") + 1) // 2
    room:moveCards({
      ids = getShade(room, num),
      to = player.id,
      toArea = Card.PlayerHand,
      moveReason = fk.ReasonPrey,
      proposer = player,
      skillName = self.name,
      moveVisible = true,
    })
  end,
})

return jiaohao